/**
  * SDL Extension for Android
  * Extension symbols are suffixed with _ext
  * @author ng
  */

#include <SDL.h>
#include "../SDL/src/render/SDL_sysrender.h"
#include <jni.h>

#include <android/log.h>

#define APPTAG "NGHSTH"
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, APPTAG,__VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG  , APPTAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO   , APPTAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN   , APPTAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR  , APPTAG,__VA_ARGS__)

/** The Android SDL window */
extern SDL_Window * Android_Window;

/*
 * Class:     org_libsdl_app_SDLActivity
 * Method:    nativeSetRendererViewport
 * Signature: (IIII)V
 */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeSetRendererViewport
(JNIEnv * e, jclass cls, jint x, jint y, jint w, jint h)
{
    SDL_Renderer * renderer = SDL_GetRenderer(Android_Window);
    SDL_Rect r = {.x = x, .y = y, .w = w, .h = h};
    SDL_RenderSetViewport(renderer, &r);

}

/*
 * Class:     org_libsdl_app_SDLActivity
 * Method:    nativeGetRendererViewport
 * Signature: ([I)V
 */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeGetRendererViewport(JNIEnv * e, jclass cls, jintArray v)
{
    jint * viewport = (*e)->GetIntArrayElements(e, v, 0);

    SDL_Renderer * renderer = SDL_GetRenderer(Android_Window);
    SDL_Rect r;
    SDL_RenderGetViewport(renderer, &r);
    viewport[0] = r.x;
    viewport[1] = r.y;
    viewport[2] = r.w;
    viewport[3] = r.h;

    (*e)->ReleaseIntArrayElements(e, v, viewport, 0);
}


